{% extends 'admin/public/base.html' %}

{% block title %}
<title>商品分类列表</title>
{% endblock %}

{% block con %}
<div class="row-content am-cf">
    <div class="row">
        <div class="am-u-sm-12 am-u-md-12 am-u-lg-12">
            <div class="widget am-cf">
                <div class="widget-head am-cf">
                    <div class="widget-title  am-cf">用户列表</div>
                </div>
                <div class="widget-body  am-fr">

                    <div class="am-u-sm-12 am-u-md-6 am-u-lg-6">
                        <div class="am-form-group">
                            <div class="am-btn-toolbar">
                                <div class="am-btn-group am-btn-group-xs">
                                    <button type="button" class="am-btn am-btn-default am-btn-success"><span class="am-icon-plus"></span> 新增</button>
                                    <button type="button" class="am-btn am-btn-default am-btn-secondary"><span class="am-icon-save"></span> 保存</button>
                                    <button type="button" class="am-btn am-btn-default am-btn-warning"><span class="am-icon-archive"></span> 审核</button>
                                    <button type="button" class="am-btn am-btn-default am-btn-danger"><span class="am-icon-trash-o"></span> 删除</button>
                                </div>
                            </div>
                        </div>
                    </div>

                    <form action="" method="get">
                      <div class="am-u-sm-12 am-u-md-6 am-u-lg-3">
                        <div class="am-form-group tpl-table-list-select">
                            <select name="types" data-am-selected="{btnSize: 'sm'}" style="display: none;">
                              <option {% if request.GET.types == 'all' %} selected {% endif %} value="all">所有类别</option>
                              <option {% if request.GET.types == 'price' %} selected {% endif %} value="price">价格</option>
                              <option {% if request.GET.types == 'title' %} selected {% endif %} value="title">标题</option>
                            <!--   <option {% if request.GET.types == 'phone' %} selected {% endif %} value="phone">家电</option>
                              <option {% if request.GET.types == 'age' %} selected {% endif %} value="age">周边</option>     --> 
                            </select>
                        </div>
                      </div>
                      <div class="am-u-sm-12 am-u-md-12 am-u-lg-3">
                        <div class="am-input-group am-input-group-sm tpl-form-border-form cl-p">
                            <input value="{{ request.GET.keywords }}" name="keywords" type="text" class="am-form-field ">
                            <span class="am-input-group-btn">
                              <button class="am-btn  am-btn-default am-btn-success tpl-table-list-field am-icon-search" ></button>
                            </span>
                        </div>
                      </div>
                    </form>

                    <div class="am-u-sm-12">
                        <table width="100%" class="am-table am-table-compact am-table-striped tpl-table-black ">
                            <thead>
                                <tr>
                                    <th>商品缩略图</th>
                                    <th>ID</th>
                                    <th>商品标题</th>
                                    <th>商品价格</th>
                                    <th>商品库存</th>
                                    <th>商品点击量</th>
                                    <th>所属分类</th>
                                    <th>状态</th>
                                    <th>发布时间</th>
                                    <th>操作</th>
                                </tr>
                            </thead>
                            <tbody>
                              {% for v in goodslist %}
                                <tr>
                                    <td>
                                       <img src="{{ v.pic }}" class="tpl-table-line-img" alt="">
                                    </td>
                                   <td class="am-text-middle typeid">{{ v.id }}</td>
                                   <td class="am-text-middle typeid">{{ v.title }}</td>
                                   <td class="am-text-middle typeid">{{ v.price }}</td>
                                   <td class="am-text-middle typeid">{{ v.num }}</td>
                                   <td class="am-text-middle typeid">{{ v.clicknum }}</td>
                                   <td class="am-text-middle typeid">{{ v.tid.name }}</td>
                                    <td class="am-text-middle">
                                        {% if  v.status == 0 %}
                                          新上架
                                        {% elif  v.status == 1 %}
                                          热卖
                                        {% elif  v.status == 2 %}
                                          下架
                                        {% else  %}
                                          删除
                                        {% endif %}
                                    </td>
                               
                                <td class="am-text-middle">{{ v.addtime|date:'Y-m-d H:i:s' }}</td>
                                <td class="am-text-middle">
                                <div class="tpl-table-black-operation">
                                    <a href="{% url 'myadmin_goods_edit' v.id %}">
                                        <i class="am-icon-pencil"></i> 编辑
                                    </a>
                                    <a href="{% url 'myadmin_goods_delete' v.id %}" class="tpl-table-black-operation-del">
                                        <i class="am-icon-trash"></i> 删除
                                    </a>
                                </div>
                                </td>
                            </tr>
                              {% endfor %}
                                <!-- more data -->
                            </tbody>
                        </table>
                    </div>
                    <div class="am-u-lg-12 am-cf">

                        <div class="am-fr">
                            <ul class="am-pagination tpl-pagination">
                               <!--  <li class="am-disabled"><a href="#">«</a></li>
                                <li class="am-active"><a href="#">1</a></li>
                                <li><a href="#">2</a></li>
                                <li><a href="#">3</a></li>
                                <li><a href="#">4</a></li>
                                <li><a href="#">5</a></li>
                                <li><a href="#">»</a></li> -->
                                <!-- {#% load pagetag %#} -->
                                {% load pagetag %}

                                {% showpage goodslist.paginator.num_pages request %}
                            </ul>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<!-- <script type="text/javascript">
    // 找到name元素,绑定双击事件
    $('table .name').dblclick(function(){
        // 获取当前元素的值,现在的类名
        var yname = $(this).text()
        var id = $(this).parents('tr').find('.typeid').text()
        // 创建以input 放置到 当前的元素位置
        var inp = $('<input type="text" value="'+yname+'" style="color:black;">')
        // 把input 加入 到当前元素的位置
        $(this).html(inp)
        inp.select()
        var span = $(this)

        // 给input绑定丧失焦点的时间
        inp.blur(function(){
            // 获取当前的input的值
            var newname = $(this).val()
            // 判断当前的name有没有修改
            if(yname == newname){
                // 没有修改
                span.html(yname)
            }else{
                // 更新 发送ajax请求,更新数据
                $.get('{% url "myadmin_types_update" %}',{'id':id,'name':newname},function(data){
                    if(data.error == 0){
                        // 成功
                        span.html(newname)
                    }
                    alert(data.msg)
                },'json')
            }
        })
    })


    // 获取删除按钮,绑定单击事件
    $('.tpl-table-black-operation-del').click(function(){
        // 获取当前的id号
        var id = $(this).parents('tr').find('.typeid').text()
        // 实例化一个 函数用于下边
        var d = $(this)
        // 发送ajax请求,传递id
        $.get('{% url "myadmin_types_delete" %}',{'id':id},function(data){
            if(data.error == 0){
                // 删除成功,删除当前的元素
                // $(this).parents('tr').remove()
                // 此处的$(this)代表的是ajax请求 XMLHttpRequest对象
                d.parents('tr').remove()
            }alert(data.msg)
        },'json')
    })  

</script>
 -->
{% endblock %}